***************************************************************************************************
/* Bridging the Gap: Lottery-based procedures in Early Parliamentarization: Replication do-file  */
***************************************************************************************************

use "BridgingtheGap_ReplicationData.dta", clear

******************
/* Descriptives */
******************

* Figure 3: Proportion of Deputy Type by Party Family
graph bar elite bourgeois other, over(encodeg, label(angle(forty_five))) scheme(s1mono) legend(order(1 "Elite" 2 "Bourgeois" 3 "Other class") cols(3)) name(encodeg, replace) 

* Figure 4: Deputy Characteristics, Chamber versus Budget Committee Under Bureaux
preserve 
keep if year<1910
foreach var of varlist elite bourgeois cm civil centrist_all {
twoway (connected prop_budget`var' year if budget==1, sort) (connected prop_budget`var' year if budget==0, sort) , scheme(s1mono) legend(order(1 "Budget members" 2 "Non-budget deputies") cols(2)) name(`var', replace) xlabel(1877 1880 (5) 1910) xmtick(1877 (1) 1910)
}
foreach var of varlist prop_budgetencodeg_* {
twoway (connected `var' year if budget==1, sort) (connected `var' year if budget==0, sort) , scheme(s1mono) legend(order(1 "Budget members" 2 "Non-budget deputies") cols(2)) name(`var', replace) xlabel(1877 1880 (5) 1910) xmtick(1877 (1) 1910)
}
foreach var of varlist age {
twoway (connected meanbudget`var' year if budget==1, sort) (connected meanbudget`var' year if budget==0, sort) , scheme(s1mono) legend(order(1 "Budget members" 2 "Non-budget deputies") cols(2)) name(`var', replace) xlabel(1877 1880 (5) 1910) xmtick(1877 (1) 1910)
}
restore


preserve
* Figure 7: Proportion of Disloyal Deputies by Party.
graph bar propdisloyalterm if term==1910 & encodeg<5, over(encodep, label(angle(45) labsize(vsmall))) over(encodeg, label(labsize(vsmall))) nofill scheme(s1mono) ytitle("Proportion of Disloyal Deputies")

sort encodeg term year
egen grouptag=tag(term encodeg propdisloyalterm)
keep if grouptag==1
keep if term<=1914
tab encodeg term,m
tab encodeg year,m
bysort encodeg term: egen meanpropdisloyal=mean(propdisloyalterm)
label variable meanpropdisloyal "Average Party Disloyalty by Party Family"
label variable year "Legislative Term"

* Figure 9: Average Disloyalty by Party Family Over Time
twoway (connected meanpropdisloyal year if encodeg==1, sort) (connected meanpropdisloyal year if encodeg==2, sort) (connected meanpropdisloyal year if encodeg==3, sort) (connected meanpropdisloyal year if encodeg==4, sort)   if term>1898&term<=1910, scheme(s1mono) legend(order(1 "Socialists" 2 "Radical-Socialists" 3 "Moderate Republicans" 4 "Right") cols(2)) name(`var', replace) xlabel(1902 1906 1910) xmtick(1902 (1) 1910)
restore

*******************
/* Sample years  */
*******************

keep if term>=1881
keep if year>=1882

******************

* Table 2: Summary Statistics
sum civil dynastic paris centrist_all switch_any switch_b1906  switch10  cm budgetexptermyears cummyears  age permargin inscrits if elite==1, separator(0)
sum civil dynastic paris centrist_all switch_any switch_b1906  switch10  cm budgetexptermyears cummyears age permargin inscrits if bourgeois==1, separator(0)
sum civil dynastic paris centrist_all switch_any switch_b1906  switch10  cm budgetexptermyears cummyears age permargin inscrits if otherclass==1, separator(0)


**********
* Analysis
**********

preserve
keep if (term>=1906 & term<=1910)
* standardise variables
foreach var of varlist *budgetexptermyears *budgetexptermyears2 *cummyears *cummyears2  *age *age2 *permargin *permargin2 *inscrits *inscrits2  {
sum `var'
replace `var'=((`var'-r(mean))/r(sd))
}
*Figure 5: Change in Log Odds of Budget Committee Selection, 1910 vs 1906
logit budget intelite elite intbourgeois bourgeois civil intcivil intdyn dynastic intparis paris intcent centrist_all int_switch_b1902 switch_b1902 int_switch_b1906 switch_b1906 switch10 intcm cm budgetexptermyears intbudgetexptermyears budgetexptermyears2 intbudgetexptermyears2 cummyears cummyears2 intcummyears intcummyears2 intage age intage2 age2 intpermargin permargin intpermargin2 permargin2 intinscrits inscrits intinscrits2 inscrits2  b1914.year   after1910   , cluster(id)  
estimates store prop
coefplot (prop)  ,   keep(intelite intbourgeois intcivil intdyn intparis intcent int_switch_b1902 int_switch_b1906 switch10 intcm) xline(0)  scheme(s1mono)
restore



preserve
keep if term==1906|term==1910
keep if diffindiffsample==1
duplicates report id

bysort term year switch_b1906: egen nrdisloyaldep=count(id)
bysort term year switch_b1906: egen totalbudgetdisloyal=total(budget)
gen prop_budgetdisloyal=totalbudgetdisloyal/nrdisloyaldep
label variable prop_budgetdisloyal "Proportion of budget members"

* Figure 6: Change in Selection probability in 1910 for Disloyal (in 1906) deputies
label variable year "Year"
twoway (connected prop_budgetdisloyal year if switch_b1906==1, sort) (connected prop_budgetdisloyal year if switch_b1906==0, sort) , scheme(s1mono) legend(order(1 "Disloyal deputies" 2 "Loyal deputies") cols(2)) name(diffindiff, replace)  xlabel(1906 (2) 1914) xmtick(1906 (1) 1914) xline(1909.5)

keep switch10 encodegroup encodeparty intencodegroup intencodeparty after1910 int_switch_b1906 switch_b1906 intelite elite intbourgeois bourgeois civil intcivil intdyn dynastic intparis paris intcent centrist_all intcm cm *permargin* *inscrits* budget *budgetexptermyears* *cummyears* *age* id term year
sort id term year
collapse (firstnm)  year encodegroup encodeparty intencodegroup intencodeparty (max) after1910 int_switch_b1906 switch_b1906 switch10 intelite elite intbourgeois bourgeois civil intcivil intdyn dynastic intparis paris intcent centrist_all intcm cm *permargin* *inscrits* budget (min) *cummyears* *age* *budgetexptermyears*, by(id term)

foreach var of varlist budgetexptermyears budgetexptermyears2 cummyears cummyears2  age age2 permargin permargin2 inscrits inscrits2  {
sum `var'
replace `var'=((`var'-r(mean))/r(sd))
}

* Table 3: Logit Regression: Party Loyalty and Budget Selection
logit budget int_switch_b1906 switch_b1906 after1910 b1906.term, cluster(id)  
logit budget int_switch_b1906 switch_b1906 after1910 switch10 elite bourgeois civil dynastic paris cm c.budgetexptermyears##c.budgetexptermyears c.cummyears##c.cummyears age age2 permargin permargin2 inscrits inscrits2 b3.encodegroup, cluster(id)  
logit budget int_switch_b1906 switch_b1906 after1910 switch10 intelite elite intbourgeois bourgeois civil intcivil intdyn dynastic intparis paris intcm cm i.after1910##c.budgetexptermyears##c.budgetexptermyears  i.after1910##c.cummyears##c.cummyears intage age intage2 age2 intpermargin permargin intpermargin2 permargin2 intinscrits inscrits intinscrits2 inscrits2 b3.encodegroup b3.intencodegroup, cluster(id)  
restore


preserve
estimates clear
keep if term==1910 & year==1910
count

* standardise variables
foreach var of varlist budgetexptermyears budgetexptermyears2 cummyears cummyears2  age age2 permargin permargin2 inscrits inscrits2 propdisloyal  {
sum `var'
replace `var'=((`var'-r(mean))/r(sd))
}
tab encodeg bureaux_reform,m r co
tab propdisloyal encodeg,m co

logit bureaux_reform elite bourgeois civil paris cm i.disloyal_ever c.propdisloyal dynastic   c.budgetexptermyears##c.budgetexptermyears c.cummyears##c.cummyears  age age2 permargin permargin2 inscrits inscrits2, r  
estimates store R
logit bureaux_reform elite bourgeois civil paris cm i.disloyal_ever c.propdisloyal b3.encodegroup dynastic  c.budgetexptermyears##c.budgetexptermyears c.cummyears##c.cummyears   age age2 permargin permargin2 inscrits inscrits2, r  
estimates store RR

*Figure 8: Log Odds of Voting for 1910 Reform
coefplot (R) || (RR) ,drop( _cons *budgetexptermyears* *cummyears* cm switch_any dynastic   age age2 permargin permargin2 inscrits inscrits2 elite bourgeois civil paris)  xline(0)    aseq     byopts(xrescale)  scheme(s1mono) legend(off)  bylabels("Controls only" "Party Family Dummies")
restore

